package main

import "fmt"

/**
 * @author: guangcheng
 * @date:   2020/11/20 14:00
 * @version  V1.0
 * @description:
 *
 */
func main() {

	var stu1 Person
	//{ 0 [0 0 0 0 0] <nil> [] map[]}
	fmt.Println(stu1)

	if stu1.ptr == nil {
		fmt.Println("ptr is nil")
	}

	if stu1.slice == nil {
		fmt.Println("slice is nil")
	}

	if stu1.map1 == nil {
		fmt.Println("map1 is nil")
	}

	stu1.slice = make([]int, 10)
	stu1.map1 = make(map[string]string)
	stu1.slice[0] = 100

	//{ 0 [0 0 0 0 0] <nil> [100 0 0 0 0 0 0 0 0 0] map[]}
	fmt.Println(stu1)

	stu1.map1["no001"] = "tomcat"
	//{ 0 [0 0 0 0 0] <nil> [100 0 0 0 0 0 0 0 0 0] map[no001:tomcat]}
	fmt.Println(stu1)

	fmt.Println("------------------------------------------")
	//不同实例之间的相同字段互不影响: 结构体属于值类型,传值
	var p1 Person
	var p2 Person
	p1.Name = "妞儿"
	p2 = p1
	//p1= {妞儿 0 [0 0 0 0 0] <nil> [] map[]} p2= {妞儿 0 [0 0 0 0 0] <nil> [] map[]}
	fmt.Println("p1=", p1, "p2=", p2)

	//实例p2的修改不会影响p1
	p2.Name = "妞妞"
	//p1= {妞儿 0 [0 0 0 0 0] <nil> [] map[]} p2= {妞妞 0 [0 0 0 0 0] <nil> [] map[]}
	fmt.Println("p1=", p1, "p2=", p2)

}

type Person struct {
	Name   string
	Age    int
	Scores [5]float64
	ptr    *int
	slice  []int
	map1   map[string]string
}
